//
//  MCMineViewController.m
//  TLYL
//
//  Created by miaocai on 2017/6/1.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMineViewController.h"
#import "MCMineHeaderView.h"
#import "MCMineTableviewCell.h"
#import "MCMineCellModel.h"
#import "MCSettingViewController.h"
#import "MCMineTitleModel.h"
#import "MCBankcardManageViewController.h"
#import "MCSecurityCenterViewController.h"
#import "MCRechargeViewController.h"
#import "MCPersonInformationViewController.h"
#import "MCTopUpRecordViewController.h"
#import "MCWithdrawRecordViewController.h"
#import "MCWithdrawViewController.h"
#import "MCGameRecordViewController.h"

@interface MCMineViewController ()
<
UITableViewDelegate,
UITableViewDataSource,
MCMineHeaderViewDelegate,
MCMineCellDelegate
>

@property (nonatomic,strong)MCMineHeaderView * view_MCMineHeader;

@property(nonatomic, strong)UITableView *tableView;

@property(nonatomic, strong)NSMutableArray*marr_Section;

@property(nonatomic, strong)NSMutableArray*marr_title;

@end

@implementation MCMineViewController

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setProperty];
    
    [self createUI];
    
    [self loadData];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=YES;
//    //设置状态栏的字体颜色模式
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//    //设置状态栏是否隐藏
//    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    
}
#pragma mark==================setProperty======================
-(void)setProperty{
    self.view.backgroundColor=RGB(239, 246, 253);
    self.navigationController.navigationBarHidden=YES;
    _marr_Section= [[NSMutableArray alloc]init];
}

#pragma mark==================createUI======================
-(void)createUI{
    /*
     *
     */
    _view_MCMineHeader=[[MCMineHeaderView alloc]init];
    [self.view addSubview:_view_MCMineHeader];
    _view_MCMineHeader.delegate=self;
    _view_MCMineHeader.frame=CGRectMake(0, 0, G_SCREENWIDTH, 200);
   
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];

    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_MCMineHeader.mas_bottom).offset(0);
        make.left.and.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view.mas_bottom).offset(-49);

    }];
}
#pragma mark==================loadData======================
-(void)loadData{
    for(int i=0 ;i<4; i++){
        CellModel* model =[[CellModel alloc]init];
        model.reuseIdentifier = [NSString stringWithFormat:@"%@--%d",NSStringFromClass([MCMineTableviewCell class]),i];
        model.className=NSStringFromClass([MCMineTableviewCell class]);
        model.height = [MCMineTableviewCell computeHeight:nil];
        model.selectionStyle=UITableViewCellSelectionStyleNone;
        model.accessoryType=UITableViewCellAccessoryNone;
        /*
         * 传递参数
         */
        model.userInfo = self.marr_title[i];
        
        SectionModel *model0=[SectionModel sectionModelWithTitle:@"" cells:@[model]];
        model0.headerhHeight=0.0001;
        model0.footerHeight=10;
        [_marr_Section addObject:model0];
    }
    [_tableView reloadData];
    
    _view_MCMineHeader.dataSource=nil;
    
}
#pragma mark tableView 代理相关
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _marr_Section.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    SectionModel *sm = _marr_Section[section];
    return sm.cells.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    SectionModel *sm = _marr_Section[section];
    return sm.headerhHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    SectionModel *sm = _marr_Section[section];
    return sm.footerHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _marr_Section[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    return cm.height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SectionModel *sm = _marr_Section[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cm.reuseIdentifier];
    if (!cell) {
        cell = [[NSClassFromString(cm.className) alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cm.reuseIdentifier];
    }
    cell.selectionStyle = cm.selectionStyle;
    
    if ([cm.className isEqualToString:NSStringFromClass([MCMineTableviewCell class])]) {
        MCMineTableviewCell *ex_cell=(MCMineTableviewCell *)cell;
        ex_cell.delegate=self;
        typeof(self) weakSelf = self;
        ex_cell.collectionViewCellDidSelectedBlock = ^(CollectionModel *model){
         
             
        
        };
        ex_cell.dataSource=cm.userInfo;
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _marr_Section[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    NSLog(@"1111---%ld",indexPath.row);
 
}
#pragma mark==================MCMineHeaderViewDelegate======================
/*
 * 跳转设置界面
 */
-(void)MCMineHeaderView_Setting{
    
    MCSettingViewController * vc=[[MCSettingViewController alloc]init];
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
    
}

/*
 * 跳转充值界面
 */
-(void)MCMineHeaderView_Recharge{
    
    MCRechargeViewController * vc = [[MCRechargeViewController alloc]init];
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
    
}

/*
 * 跳转提现
 */
-(void)MCMineHeaderView_Withdraw{
    MCWithdrawViewController * vc=[[MCWithdrawViewController alloc]init];
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
}

/*
 * 跳转站内信
 */
-(void)MCMineHeaderView_Message{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSMutableArray *)marr_title{
    if (!_marr_title) {
        _marr_title =[[NSMutableArray alloc]init];
        MCMineTitleModel * model0=[MCMineTitleModel getModelWithMainTitle:@"我的账户" andSubTitle:@[@"个人资料",@"银行卡管理",@"安全中心"]];
        [_marr_title addObject:model0];
        MCMineTitleModel * model1=[MCMineTitleModel getModelWithMainTitle:@"财务中心" andSubTitle:@[@"充值记录",@"提款记录"]];
        [_marr_title addObject:model1];
        MCMineTitleModel * model2=[MCMineTitleModel getModelWithMainTitle:@"订单报表" andSubTitle:@[@"游戏记录",@"追号记录",@"帐变记录",@"个人报表"]];
        [_marr_title addObject:model2];
        MCMineTitleModel * model3=[MCMineTitleModel getModelWithMainTitle:@"团队报表" andSubTitle:@[@"开户中心",@"会员管理",@"契约管理",@"团队报表"]];
        [_marr_title addObject:model3];
    }
    return _marr_title;
}

-(void)MCMineCell_Click:(NSString *)type{
    
        UIViewController * vc = nil;
        self.navigationController.navigationBarHidden=NO;
        if ([type isEqualToString:@"个人资料"]) {
        /*
        * 跳转个人资料
        */

        vc =[[MCPersonInformationViewController alloc]init];

        }else if ([type isEqualToString:@"银行卡管理"]){
        vc=[[MCBankcardManageViewController alloc]init];
        }else if ([type isEqualToString:@"安全中心"]){

        vc=[[MCSecurityCenterViewController alloc]init];
        }else if ([type isEqualToString:@"充值记录"]){
            
        vc=[[MCTopUpRecordViewController alloc]init];
            
        }else if ([type isEqualToString:@"提款记录"]){
            
        vc=[[MCWithdrawRecordViewController alloc]init];
            
        }else if ([type isEqualToString:@"游戏记录"]){
            
        vc = [[MCGameRecordViewController alloc] init];
            
        }else if ([type isEqualToString:@"追号记录"]){
            
        }else if ([type isEqualToString:@"帐变记录"]){

        }else if ([type isEqualToString:@"个人报表"]){
        }else if ([type isEqualToString:@"开户中心"]){
          
        }else if ([type isEqualToString:@"会员管理"]){

        }else if ([type isEqualToString:@"契约管理"]){
        }else if ([type isEqualToString:@"团队报表"]){
           
        }
    if (vc == nil) {
        return;
    }
    [self.navigationController pushViewController:vc animated:YES];
}
@end










































